package com.cbgolf.oa.activity.statistics;

import android.os.Bundle;
import com.cbgolf.oa.R;
import com.cbgolf.oa.activity.BaseNewActivity;
import com.cbgolf.oa.activity.closepark.CloseParkListActivity;
import com.cbgolf.oa.contract.ITeetimeContract;
import com.cbgolf.oa.entity.TeeTimeBean.TeeTimesBean;
import com.cbgolf.oa.event.Events;
import com.cbgolf.oa.presenter.TeetimePresenterImpl;
import com.cbgolf.oa.views.TeetimeViewImp;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * @author Created by lq on 2018/1/5.
 */
public class TeetimeActivity extends BaseNewActivity implements ITeetimeContract.Waiter {

  private ITeetimeContract.Presenter presenter;
  private ITeetimeContract.IView view;

  @Override
  protected int getLayoutId() {
    return R.layout.a_teetime;
  }

  @Override
  protected void init(Bundle savedInstanceState) {
    EventBus.getDefault().register(this);
    view = new TeetimeViewImp(this, this);
    presenter = new TeetimePresenterImpl();
    presenter.init(view);
    presenter.requestAbCode();
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    EventBus.getDefault().unregister(this);
  }

  @Override
  public String getActivityTitle() {
    return "Teetime";
  }

  @Override
  public void back() {
    finish();
  }

  @Subscribe(threadMode = ThreadMode.MAIN)
  public void requestOver(Events events) {
    if (null != view) {
      view.requestOver(events);
    }
  }

  @Override
  public void requestTeetime(long time, String abCode) {
    presenter.requestTeetime(time, abCode);
  }

  @Override
  public void refresh() {
    presenter.requestTeetime(0, null);
  }

  @Override
  public void addPerson(TeeTimesBean bean) {
    if (null == bean) {
      return;
    }
    view.showProgress();
    presenter.addPerson(bean);
  }

  @Override
  public void reducePerson(TeeTimesBean bean) {
    if (null == bean) {
      return;
    }
    view.showProgress();
    presenter.reducePerson(bean);
  }

  @Override
  public void showCloseParkList() {
    mStartActivity(CloseParkListActivity.class);
  }

}
